###Search for simple gene rifs for a set of genes
###Start for testing stuff

###library(annotate)
###library(hgu133plus2)
###geneList <- c("240856_at","1562921_at","237183_at","241391_at","238061_at",
###"213664_at","226420_at","222073_at","216682_s_at","239246_at")


rifFinder <- function(geneList,entrezIDenv,searchString = NULL){
 ##keywords can be written as e.g."teleomerase|cancer"
 
 rifTable <- read.table(file = "c:/MiiR/rifs/generifs_basic.txt",skip = 22654,
                        header = F,sep = "\t",nrows = 216003,quote = "",
                        colClasses = "character")
 
 if(!is.null(searchString)){
  rifTable <- rifTable[grep(searchString,x=rifTable[,5]) ,] 
 }
 
 entrezIDs <- mget(geneList,env = entrezIDenv)
 rifs <- entrezIDs

 for (gene in geneList){
  if(!is.na(entrezIDs[[gene]]) & any(rifTable[,2] == entrezIDs[[gene]])){
   rifs[[gene]] <- rifTable[rifTable[,2] == entrezIDs[[gene]],c(3,5)]
  }
  else{
  rifs[[gene]] <- NA
  } 
 }

 return(rifs)
}